<?php

namespace KyleWechat;

class App
{
    /**
     * 应用实例
     * @var WechatServer
     */
    protected $app;

    /**
     * 构造方法
     * @access public
     */
    public function __construct()
    {
        $this->app = WechatServer::getApp();
    }

    /**
     * 解析拼接url
     * @param $url
     * @param $params
     * @return string
     */
    public function parseUrl($url, $params): string
    {
        $data = parse_url($url);
        $params = http_build_query($params);
        $query = $data['query']??'';
        if ($query || strpos($url,'?') !== false){
            $url .= '&'.$params;
        }else{
            $url .= '?'.$params;
        }
        return $url;
    }

    public function random($length = 6)
    {
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        $chars = str_shuffle($chars);
        return substr($chars,0,$length);
    }
}